Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
path-exists
Advanced tools
The path-exists npm package is used to check if a file or directory exists on the file system without using fs.existsSync. It is built on top of Node.js's fs.promises API and provides a simple promise-based interface.
Check if a path exists
This feature allows you to check if a file or directory exists asynchronously by returning a promise that resolves to either true or false.
const pathExists = require('path-exists');
(async () => {
const exists = await pathExists('/path/to/file');
console.log(exists);
//=> true or false
})();
Check if a path exists synchronously
This feature provides a synchronous way to check if a file or directory exists, returning a boolean value immediately.
const pathExists = require('path-exists');
const exists = pathExists.sync('/path/to/file');
console.log(exists);
//=> true or false
fs-extra is a package that extends the built-in fs module, providing additional methods and ensuring consistency across platforms. It includes the 'pathExists' and 'pathExistsSync' methods, which are similar to the functionality provided by path-exists. fs-extra offers a broader set of file system operations, making it a more comprehensive choice for file system interactions.
make-dir is a package that focuses on creating directories and their parent directories if they don't exist. While it doesn't provide a direct method to check for the existence of a path, it is related in the sense that it handles the existence of directories as part of its operation. It differs from path-exists as it is more about directory creation than existence checking.
Check if a path exists
NOTE: fs.existsSync
has been un-deprecated in Node.js since 6.8.0. If you only need to check synchronously, this module is not needed.
Never use this before handling a file though:
In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to
fs.exists()
andfs.open()
. Just open the file and handle the error when it's not there.
$ npm install path-exists
// foo.js
import {pathExists} from 'path-exists';
console.log(await pathExists('foo.js'));
//=> true
Returns a Promise<boolean>
of whether the path exists.
Returns a boolean
of whether the path exists.
FAQs
Check if a path exists
We found that path-exists demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.